Attribute VB_Name = "GameMedia"
'====================================================================================
'GameMedia - Storage of the game graphics and sound effects
'====================================================================================
Option Explicit

'--- Graphics -----------------------------------------------------------------------
'Controller for managing particle effects
Public Particles As clsParticleHandler

'Shared graphics across the program (these are preloaded very early on)
Public Type PM_GFX
    TitleLogo As New ImageTGA    'The Pac Mar title logo
    TitleBadge As New ImageTGA   'The title badge
End Type
Public GFX As PM_GFX

'A central place to store the main game sprites
Public Type PM_SPRITESET
    'Static sprites
    Cookie As New ImageTGA       'The cookie(s) used in the game
    Heart As New ImageTGA        'The power heart
    Pie As New ImageTGA          'The random pie pickup
    'Main sprites
    Mar(4) As New ImageTGA       'Mar's animations
    Ghosts(1 To 4, 2) As New ImageTGA
End Type
Public Sprites As PM_SPRITESET

'--- Sound Effects ------------------------------------------------------------------
Public Type PM_SFX
    Running As New clsSFX
    CookieCrunch As New clsSFX
    EatHeart As New clsSFX
    EatGhost As New clsSFX
    Death As New clsSFX
End Type
Public SFX As PM_SFX

'====================================================================================
'LoadResources: Read in the common graphics, sprites and sounds
'====================================================================================
Public Sub LoadResources()
    'Load the fonts
    With Fonts
        .Pinball.Load AppPath & "\gfx\Fonts\Pinball"
        .Menu.Load AppPath & "\gfx\Fonts\Menu"
        .Pastel.Load AppPath & "\gfx\Fonts\Pastel"
        .Keys.Load AppPath & "\gfx\Fonts\Keys"
    End With
    'Load the shared graphics
    With GFX
        .TitleLogo.LoadTGA32 AppPath & "\gfx\Titles\TitleLogo.tga"
        .TitleBadge.LoadTGA32 AppPath & "\gfx\Titles\TitleBadge.tga"
    End With
    
    'Load the game sprites, a lot of screens use these so they're loaded early
    With Sprites
        'Load the static sprites
        .Cookie.LoadTGA32 AppPath & "\gfx\Sprites\Cookie.tga"
        .Heart.LoadTGA32 AppPath & "\gfx\Sprites\Heart.tga"
        .Pie.LoadTGA32 AppPath & "\gfx\Sprites\Pie.tga", True
        
        'Load Pac Mar's sprites
        .Mar(0).LoadTGA32 AppPath & "\gfx\Sprites\PacMar_u.tga", True
        .Mar(1).LoadTGA32 AppPath & "\gfx\Sprites\PacMar_r.tga", True
        .Mar(2).LoadTGA32 AppPath & "\gfx\Sprites\PacMar_d.tga", True
        .Mar(3).LoadTGA32 AppPath & "\gfx\Sprites\PacMar_l.tga", True
        .Mar(4).LoadTGA32 AppPath & "\gfx\Sprites\PacMar_Dead.tga", True
        
        'Load the ghosts
        .Ghosts(GT_Zim, 0).LoadTGA32 AppPath & "\gfx\Sprites\Zim.tga", True
        .Ghosts(GT_Zim, 1).LoadTGA32 AppPath & "\gfx\Sprites\ZimLove.tga", True
        .Ghosts(GT_Zim, 2).LoadTGA32 AppPath & "\gfx\Sprites\ZimEaten.tga", True
        .Ghosts(GT_Dib, 0).LoadTGA32 AppPath & "\gfx\Sprites\Dib.tga", True
        .Ghosts(GT_Dib, 1).LoadTGA32 AppPath & "\gfx\Sprites\DibLove.tga", True
        .Ghosts(GT_Dib, 2).LoadTGA32 AppPath & "\gfx\Sprites\DibEaten.tga", True
        .Ghosts(GT_Kroc, 0).LoadTGA32 AppPath & "\gfx\Sprites\Kroc.tga", True
        .Ghosts(GT_Kroc, 1).LoadTGA32 AppPath & "\gfx\Sprites\KrocLove.tga", True
        .Ghosts(GT_Kroc, 2).LoadTGA32 AppPath & "\gfx\Sprites\KrocEaten.tga", True
        .Ghosts(GT_Gir, 0).LoadTGA32 AppPath & "\gfx\Sprites\Gir.tga", True
        .Ghosts(GT_Gir, 1).LoadTGA32 AppPath & "\gfx\Sprites\GirLove.tga", True
        .Ghosts(GT_Gir, 2).LoadTGA32 AppPath & "\gfx\Sprites\GirEaten.tga", True
    End With
    
    'Preload the game sound effects (this is ignored if you use -nosfx option)
    If InStr(1, Command(), "-nosfx") = 0 Then
        SFX.Running.Load AppPath & "\sfx\Running.wav"
        SFX.CookieCrunch.Load AppPath & "\sfx\T~crunch1.wav"
        SFX.Death.Load AppPath & "\sfx\pacmardies.wav"
        SFX.EatGhost.Load AppPath & "\sfx\enemyeat.wav"
        SFX.EatHeart.Load AppPath & "\sfx\eatheart.wav"
    End If
End Sub

'====================================================================================
'UnloadResources
'====================================================================================
Public Function UnloadResources()
    'Unload fonts
    With Fonts
        Set .Menu = Nothing
        Set .Pastel = Nothing
        Set .Pinball = Nothing
        Set .Keys = Nothing
    End With
    'Unload shared graphics
    With GFX
        Set .TitleLogo = Nothing
        Set .TitleBadge = Nothing
    End With
    'Unload the sprites (that arn't in arrays)
    With Sprites
        Set .Cookie = Nothing
        Set .Heart = Nothing
        Set .Pie = Nothing
    End With
    'Unload all the sound effects
    With SFX
        Set .Running = Nothing
        Set .CookieCrunch = Nothing
        Set .Death = Nothing
        Set .EatGhost = Nothing
        Set .EatHeart = Nothing
    End With
    
    Erase Sprites.Mar     'Unload the Mar sprite
    Erase Sprites.Ghosts  'Unload the ghosts
End Function

'====================================================================================
'DrawPacMarTitle: Draw the Pac Mar title, a number of screens use this image
'====================================================================================
Public Sub DrawPacMarTitle(ByVal hDC As Long, ByVal Y As Long, Optional ByVal Message As String = "", Optional ByVal IncludeBadge As Boolean = True)
    Dim Width As Long
    'Cache the text (and its width) under the title
    If Message <> "" Then Width = GameText.Fonts.Pastel.GetTextWidth(Message)
    
    'Draw the main Pac Mar logo on the main screen
    GFX.TitleLogo.Draw hDC, 93, Y
    'Draw on the sub title
    If Message <> "" Then Fonts.Pastel.DrawText hDC, (640 - Width) \ 2, Y + 117, Message
    'Draw on the Title Badge
    GFX.TitleBadge.Draw hDC, 70, Y - 13
    
    'Draw rotated text onto the title badge
    Dim hFont As Long, hOld As Long, Msg As String
    hFont = SharedAPI.CreateFont(17, 0, 210, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH Or FF_DONTCARE, "Century Gothic")
    SharedAPI.SetBkMode hDC, 0
    hOld = SharedAPI.SelectObject(hDC, hFont)
    SharedAPI.SetTextColor hDC, vbWhite
    SharedAPI.SetTextAlign hDC, TA_TOPCENTER
    
    Msg = "v" & VB.App.Major & "." & VB.App.Minor
    SharedAPI.TextOut hDC, 88, Y - 5, Msg, Len(Msg)
    
    Msg = "b" & VB.App.Revision
    SharedAPI.TextOut hDC, 94, Y + 8, Msg, Len(Msg)
    
    SharedAPI.SelectObject hDC, hOld
    SharedAPI.DeleteObject hFont
End Sub

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
